package com.example.sharding.controller;

import com.example.sharding.common.ICCResult;
import com.example.sharding.domain.User;
import com.example.sharding.service.UniqueIdService;
import com.example.sharding.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author admin
 */
@RestController
@Controller
public class UserController {


    @Autowired
    private UserService userService;

    @Autowired
    private UniqueIdService uniqueIdService;

    @GetMapping("/getAll")
    private ICCResult getAll() {
        List<User> a=userService.getAll();
        return ICCResult.success(a);
    }

    @PostMapping("/insert")
    private ICCResult insert(User user) {
        System.out.println(user.toString());
        int i=userService.inset(user);
        return ICCResult.success(i);
    }

    @GetMapping("/getId")
    private ICCResult getId() {
        long id = uniqueIdService.generateUniqueId();
        return ICCResult.success(id);
    }

}
